programming4us
           
 
 
Windows

Windows 7 : Working with the Command-Line Tools (part 3) - Working with System Management Tools

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
12/7/2010 11:22:58 AM

Working with System Management Tools

System management is one of those catch-all terms that encompasses a wide range of tasks, from simple adjustments such as changing the system date and time to more complex tweaks such as modifying the Registry. Windows 7’s command-line system management tools also enable you to monitor system performance, shut down or restart the computer, and even modify the huge Windows Management Instrumentation (WMI) interface. Table 4 lists the system management command-line tools that apply to Windows 7.

Table 4. Windows 7’s Command-Line System Management Tools
ToolDescription
BCDEDITDisplays or modifies the Boot Manager startup parameters
CHCPDisplays or changes the number of active console code pages
DATEDisplays or sets the system date
EVENTCREATECreates a custom event in an event log
REGAdds, modifies, displays, and deletes Registry keys and settings
REGSVR32Registers dynamic link library (DLL) files as command components in the Registry
SHUTDOWNShuts down or restarts Windows 7 or a remote computer
SYSTEMINFODisplays a wide range of detailed configuration information about the computer
TIMEDisplays or sets the system time
TYPEPERFMonitors a performance counter
WHOAMIDisplays information about the current user, including the domain name (not applicable to Windows 7), computer name, username, security group membership, and security privileges
WMICOperates the Windows Management Instrumentation command-line tool that provides command-line access to the WMI interface

The next few sections take more detailed looks at five of these command-line tools: REG, SYSTEMINFO, TYPEPERF, and WHOAMI.

REG: Working with Registry Keys and Settings

That’s the easiest and safest way to make Registry changes. However, there may be some settings that you change quite often. In such cases, it can become burdensome to be frequently launching the Registry Editor and changing the settings. A better idea is to create a shortcut or batch file that uses the REG command-line tool to make your Registry changes for you.

REG actually consists of 11 subcommands, each of which enables you to perform different Registry tasks:

REG ADDAdds new keys or settings to the Registry. You can also use this command to modify existing settings.
REG QUERYDisplays the current values of one or more settings in one or more keys.
REG COMPARECompares the values of two Registry keys or settings.
REG COPYCopies Registry keys or settings to another part of the Registry.
REG DELETEDeletes a key or setting.
REG EXPORTExports a key to a .reg file.
REG IMPORTImports the contents of a .reg file.
REG SAVECopies Registry keys or settings to a hive (.hiv) file.
REG RESTOREWrites a hive file into an existing Registry key. The hive file must be created using REG SAVE.
REG LOADLoads a hive file into a new Registry key. The hive file must be created using REG SAVE.
REG UNLOADUnloads a hive file that was loaded using REG LOAD.

I won’t go through all of these commands. Instead, I’ll focus on the three most common Registry tasks: viewing, adding, and modifying Registry data.

To view the current value of the Registry setting, you use the REG QUERY command:

REG QUERY KeyName [/V SettingName | /VE] [/C] [/D] [/E] [/F data] [/K | [/S] [/SE separator] [/T type] [/Z]


KeyNameThe Registry key that contains the setting or settings that you want to view. The KeyName must include a root key value: HKCR, HKCU, HKLM, HKU, or HKCC. Place quotation marks around key names that include spaces.
/V ValueNameThe Registry setting in KeyName that you want to view.
/VETells REG to look for empty settings (that is, settings with a null value).
/F dataSpecifies the data that REG should match in the KeyName settings.
/CRuns a case-sensitive query.
/EReturns only exact matches.
/KQueries only key names, not settings.
/STells REG to query the subkeys of KeyName.
/SE separatorDefines the separator to search for in REG_MULTI_SZ settings.
/T typeSpecifies the setting type or types to search: REG_SZ, REG_MULTI_SZ, REG_EXPAND_SZ, REG_DWORD, REG_BINARY, or REG_NONE.
/ZTells REG to include the numeric equivalent of the setting type in the query results.

For example, if you want to know the current value of the RegisteredOwner setting in HKLM\Software\Microsoft\Windows NT\CurrentVersion, run the following command:

reg query "hklm\software\microsoft\windows nt\currentversion" registeredowner

The Registry Editor has a Find command that enables you to look for text within the Registry. However, it would occasionally be useful to see a list of the Registry keys and settings that contains a particular bit of text. You can do this using the /F switch. For example, suppose you want to see a list of all the HKLM keys and settings that contain the text Windows Defender. Here’s a command that will do this:
reg query hklm /f "Windows Defender" /s

To add a key or setting to the Registry, use the REG ADD command:

REG ADD KeyName [/V SettingName | /VE] [/D data] [/F | [/S separator] [/T type]


KeyNameThe Registry key that you want to add or to which you want to add a setting. The KeyName must include a root key value: HKCR, HKCU, HKLM, HKU, or HKCC. Place quotation marks around key names that include spaces.
/V ValueNameThe setting that you want to add to KeyName.
/VETells REG to add an empty setting.
/D dataSpecifies the data that REG should use as the value for the new setting.
/FModifies an existing key or setting without prompting to confirm the change.
/S separatorDefines the separator to use between multiple instances of data in a new REG_MULTI_SZ setting.
/T typeSpecifies the setting type: REG_SZ, REG_MULTI_SZ, REG_EXPAND_SZ, REG_DWORD, REG_DWORD_BIG_ENDIAN, REG_DWORD_LITTLE_ENDIAN, REG_BINARY, or REG_LINK.

For example, the following command adds a key named MySettings to the HKCU root key:

reg add hkcu\MySettings

Here’s another example that adds a setting named CurrentProject to the new MySettings key and sets the value of the new setting to Win7 Unleashed:

reg add hkcu\MySettings /v CurrentProject /d "Win7 Unleashed"

If you want to make changes to an existing setting, run REG ADD on the setting. For example, to change the HKCU\MySettings\CurrentProject setting to Windows 7 Unleashed, you run the following command:

reg add hkcu\MySettings /v CurrentProject /d "Windows 7 Unleashed"

Windows 7 responds with the following prompt:

Value CurrentProject exists, overwrite (Yes/No)?

To change the existing value, press Y and press Enter.

Tip

To avoid being prompted when changing existing settings, add the /F switch to the REG ADD command.


SYSTEMINFO: Returning System Configuration Data

If you want to get information about various aspects of your computer, a good place to start is the SYSTEMINFO command-line tool, which displays data about the following aspects of your system:

  • The operating system name, version, and configuration type

  • The registered owner and organization

  • The original install date

  • The system boot time

  • The computer manufacturer, make, and model

  • The system processors

  • The BIOS version

  • The total and available physical memory

  • The paging file’s maximum size, available size, in-use value, and location

  • The installed hotfixes

  • The network interface card data, such as the name, connection, DHCP status, and IP address (or addresses)

You can see all this data (and more), as well as control the output, by running SYSTEMINFO with the following syntax:

SYSTEMINFO [/S computer] [/U [domain]\username] [/P password] [/FO format] [/NH]


/S computerThe name of the remote computer for which you want to view the system configuration.
/U [domain]\usernameThe username and, optionally, the domain, of the account under which you want to run the SYSTEMINFO command.
/P passwordThe password of the account you specified with /U.
/FO formatThe output format, where format is one of the following values:
 tableThe output is displayed in a row-and-column format, with headers in the first row and values in subsequent rows.
 listThe output is displayed in a two-column list, with the headers in the first column and values in the second column.
 csvThe output is displayed with headers and values separated by commas. The headers appear on the first line.
/NHTells SYSTEMINFO not to include column headers when you use the /FO switch with either table or csv.

The output of SYSTEMINFO is quite long, so pipe it through the MORE command to see the output one screen at a time:

systeminfo | more

If you want to examine the output in another program or import the results into Excel or Access, redirect the output to a file and use the appropriate format. For example, Excel can read .csv files, so you can redirect the SYSTEMINFO output to a .csv file while using csv as the output format:

systeminfo /fo csv > systeminfo.csv

TYPEPERF: Monitoring Performance
You can get the same benefit without the Performance Monitor GUI by using the powerful TYPEPERF command-line tool. Here’s the syntax:
TYPEPERF [counter1 [counter2 ...]] [-CF file] [-O file] [-F format] [-SI interval] [-SC samples] [-Q [object]] [-QX [object]] [-CONFIG file] [-S computer]


counter1 [counter2 ...]Specifies the path of the performance counter to monitor. If you want to track multiple counters, separate each counter path with a space. If any path includes spaces, surround the path with quotation marks.
-CF fileLoads the counters from file, where file is a text file that lists the counter paths on separate lines.
-O fileSpecifies the path and name of the file that will store the performance data.
-F formatSpecifies the format for the output file format given by the /O switch, where format is one of the following values:
 csvThe output is displayed with each counter separated by a comma and each sample on its own line. This is the default output format.
 tsvThe output is displayed with each counter separated by a tab and each sample on its own line.
 binThe output is displayed in binary format.
-SI intervalSpecifies the time interval between samples. The interval parameter uses the form [mm:] ss. The default interval is 1 second.
-SC samplesSpecifies the number of samples to collect. If you omit this switch, TYPEPERF samples continuously until you press Ctrl+C to cancel.
-Q [object]Lists the available counters for object without instances.
-QX [object]Lists the available counters for object with instances.
-CONFIG fileSpecifies the pathname of the settings file that contains the TYPEPERF parameters you want to run.
-S computerSpecifies that the performance counters should be monitored on the PC named computer if no computer name is specified in the counter path.
-YAnswers yes to any prompts generated by TYPEPERF.

The official syntax of a counter path looks like this:

[\\Computer]\Object([Parent/][Instance][#Index])\Counter

ComputerThe computer on which the counter is to be monitored. If you omit a computer name, TYPEPERF monitors the counter on the local computer.
ObjectThe performance object—such as Processor, Memory, or PhysicalDisk—that contains the counter.
ParentThe container instance of the specified Instance.
InstanceThe instance of the Object, if it has multiple instances. For example, in a two- (or dual-core) processor system, the instances are 0 (for the first processor), 1 (for the second processor), or Total (for both processors combined). You can also using an asterisk (*) to represent all the instances in Object.
IndexThe index number of the specified Instance.
CounterThe name of the performance counter. You can also use an asterisk (*) to represent all the counter in Object(Instance).

In practice, however, you rarely use the Computer, Parent, and Index parts of the path, so most counter paths use one of the following two formats:

\Object\Counter
\Object(Instance)\Counter

For example, here’s the path for the Memory object’s Available MBytes counter:

\Memory\Available MBytes

Here’s a TYPEPERF command that displays five samples of this counter:

typeperf "\Memory\Available Mbytes" -sc 5

Similarly, here’s the path for the Processor object’s % Processor Time counter, using the first processor instance:

\Processor(0)\% Processor Time

Here’s a TYPEPERF command that displays 10 samples of this counter every 3 seconds, and saves the results to a file named ProcessorTime.txt:

typeperf "\Processor(0)\% Processor Time" -sc 10 -si 3 -o ProcessorTime.txt

To use the -CONFIG parameter with TYPEPERF, you need to create a text file that stores the command line parameters you want to use. This configuration file consists of a series of parameter/value pairs that use the following general format:

[Parameter]
Value

Here, Parameter is text that specifies a TYPEPERF parameter—such as F for the -F parameter and S for the -S parameter. Use C to specify one or more counter paths—and Value is the value you want to assign to the parameter.

For example, consider the following command:

typeperf "\PhysicalDisk(_Total)\% Idle Time" -si 5 -sc 10 -o idletime.txt

To run the same command using the -CONFIG parameter, you first need to create a file with the following text:

[c]
\PhysicalDisk(_Total)\% Idle Time
[si]
5
[sc]
10
[o]
idletime.txt

If this file is named IdleTimeCounter.txt, you can run it at any time with the following command (assuming IdleTimeCounter.txt resides in the current folder):

typeperf -config IdleTimeCounter.txt

WHOAMI: Getting Information About the Current User

The WHOAMI command gives you information about the user who is currently logged on to the computer:

WHOAMI [/UPN | /FQDN | LOGONID] [/USER | /GROUPS | /PRIV] [/ALL] [/FO Format]


/UPN(Domains only) Returns the current user’s name using the user principal name (UPN) format.
/FQDN(Domains only) Returns the current user’s name using the fully qualified domain name (FQDN) format.
/LOGONIDReturns the current user’s security identifier (SID).
/USERReturns the current username using the computer\user format.
/GROUPSReturns the groups of which the current user is a member.
/PRIVReturns the current user’s privileges.
/ALLReturns the current user’s SID, username, groups, and privileges.
/FO formatThe output format, where format is one of the following values:
 tableThe output is displayed in a row-and-column format, with headers in the first row and values in subsequent rows.
 listThe output is displayed in a two-column list, with the headers in the first column and values in the second column.
 csvThe output is displayed with headers and values separated by commas. The headers appear on the first line.

You probably won’t use this command often on the Windows 7 computer because you’ll almost always be logged on as administrator. However, WHOAMI is useful when you’re working on a client computer and you’re not sure who is currently logged on.

For example, the following command redirects the current user’s SID, username, groups, and privileges to a file named whoami.txt using the list format:

whoami /all /fo list > whoami.txt
Other -----------------
- SOA with .NET and Windows Azure : System.Transactions
- Windows 7 : Understanding Batch File Basics (part 2) - Using Batch File Parameters
- Windows 7 : Understanding Batch File Basics (part 1) - Creating Batch Files
- Discovering the Microsoft Azure Platform
- SOA with .NET and Windows Azure : Microsoft Messaging Queue (MSMQ)
- Windows 7 : Working at the Command Line (part 3)
- Windows 7 : Working at the Command Line (part 2)
- Windows 7 : Working at the Command Line (part 1)
- Windows 7 : Getting to the Command Line (part 2) - Running CMD
- Windows 7 : Getting to the Command Line (part 1)
- Windows Azure : Programming Access Control Service (part 10) - Deploying the Web Service in Windows Azure
- Windows Azure : Programming Access Control Service (part 9) - Configuring a Web Service Client to Acquire and Send SAML Tokens
- Windows Azure : Programming Access Control Service (part 8)
- Windows Azure : Programming Access Control Service (part 7) - Integrating ACS with a SAML Token Provider
- Windows Azure : Programming Access Control Service (part 6)
- Windows Azure : Programming Access Control Service (part 5)
- Windows Azure : Programming Access Control Service (part 4)
- Windows Azure : Programming Access Control Service (part 3)
- Windows Azure : Programming Access Control Service (part 2)
- Windows Azure : Programming Access Control Service (part 1)
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us